#ifndef _ASYNCTCPSOCKIMPL_H_
#define _ASYNCTCPSOCKIMPL_H_

#include "stdafx.h"
#include <io/iasynio.h>

#include "ioimpl/iotcpbase.h"
#include "ioimpl/iostreambase.h"
uvNameSpace


class CAsyncTcpSocketImpl :	public	IAsyncTcpSocket,
							public	CUnknownImp
{
public:
	CAsyncTcpSocketImpl(void);
	virtual ~CAsyncTcpSocketImpl(void);
	UNKNOWN_IMP1(IAsyncTcpSocket);
	//////////////////////////////////////////////////////////////////////////
	//IIoDevice
	std_method(ReadIo)(IIoOperation* pOperation);
	std_method(WriteIo)(IIoOperation* pOperation);
	std_method(ReadAllIo)(IIoOperation* pOperation);
	std_method(WriteAllIo)(IIoOperation* pOperation);
	std_method(ConnectIo)(IIoOperation* pOperation);
	std_method(AcceptConnect)(IIoOperation* pOperation);
	std_method(CloseIo)();
	std_method(OpenIo)();
	std_method(BindIo)();
	//////////////////////////////////////////////////////////////////////////
	//ISocket
	std_method_(os_sock_t, GetSocket)();
	std_method(BindSocket)(os_sock_t sock);
	//////////////////////////////////////////////////////////////////////////
	//ITcpSocket
	std_method(SetReuseAddr)(bool bstart);
	std_method(SetNoDelay)(bool bstart);
	std_method(SetLinger)(bool bstart);
	std_method(SetKeepalive)(bool bstart);
	std_method(SetCork)(bool bstart);
	std_method(SetNoSigPipe)(bool bstart);
	std_method(SetNonblock)(bool bstart);
	std_method(SendBufLen)(ULONG size);
	std_method(RecvBufLen)(ULONG size);
	std_method(SendTimeOut)(int sec);
	std_method(RecvTimeOut)(int sec);
	std_method(ConnectTimeOut)(int sec);
	std_method(SendLoWat)(int size);
	std_method(RecvLoWat)(int size);
	//////////////////////////////////////////////////////////////////////////
	//IAsynTcpSocket
	//////////////////////////////////////////////////////////////////////////
	os_sock_t									m_socketFd;
	sentry<io_tcp_i*,default_sentry>			m_tcp;
	sentry<io_streambase_t*,default_sentry>		m_stream;

	ULONG										m_ulRecvBufLen;
	ULONG										m_ulSendBufLen;
	ULONG										m_ulConnectTimeoutSec;
private:
	
private:
	static void	StreamOpenProc(io_tcp_i *pData, int iStatus);
	static void	AsyncWokerProc(void *pData);
	static void	StreamWriteProc(io_streambase_t* pData, unsigned long ulen);
	static void	StreamReadProc(io_streambase_t* pData, unsigned long ulen);
	static void	StreamEventProc(io_streambase_t* pData, short what);

};







#endif